package com.jsu.hotelmanagement.observerModel;


import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.jsu.hotelmanagement.observerModel.thread.CheckOut;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * @author yangxiyuan
 */
@Component
public class ObserverModelApplication {


    final
    CheckOut checkOut;

    private static ExecutorService executorService;

    public ObserverModelApplication(CheckOut checkOut) {
        this.checkOut = checkOut;
    }

    public static ExecutorService getExecutorService() {
        return executorService;
    }



    public void run(){
        ThreadFactory checkOutThread = new ThreadFactoryBuilder().setNameFormat("创建退房检测线程的工厂").build();

        executorService = new ThreadPoolExecutor(
                65,
                65,
                650,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                checkOutThread,
                new ThreadPoolExecutor.CallerRunsPolicy());

        executorService.execute(checkOut);
    }


}
